package publishSubscribe;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public class Subscriber implements PropertyChangeListener {

    private final Person person;
    private Publisher publisher;

    Subscriber(Person p, Publisher publisher) {
        this.person = p;
        publisher.registerSubscriber(this);
    }

    private void subscribe(Publisher publisher) {
        publisher.registerSubscriber(this);
    }

    @Override
    public void propertyChange(PropertyChangeEvent event) {
        System.out.println(event.getSource().getClass().toString() + " // Beobachter  meldet: " + person.getName() + " " + event.getPropertyName() + " [geändert: "
                + event.getOldValue() + "] | [neu: " + event.getNewValue() + "] erhalten");
    }
}
